import { ref } from 'vue'
import { defineStore } from 'pinia'
//缓存令牌
export const useTokenStore = defineStore(
  'Authorization',
  () => {
    const Authorization = ref(null)

    const getToken = () => {
      return Authorization.value || localStorage.getItem('Authorization')
    }
    const setToken = (data) => {
      Authorization.value = 'Bearer ' + data
      localStorage.setItem('Authorization', Authorization.value)
    }
    const removeToken = () => {
      Authorization.value = ''
      localStorage.removeItem('Authorization')
    }
    return { Authorization, setToken, getToken, removeToken }
  },
  {
    persist: true // 持久化
  }
)
